package cz.pproproj.aaservice.aasdbmodule.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@Entity(name = "AasDbMappingDAO")
@Table(name = "MAPPINGS")
public class AasDbMappingDAO {

    private int _id;

    private String _dataSource;

    private String _userName;

    private List<AasDbUserRoleDAO> _roles;

    public AasDbMappingDAO() {
    }

    public AasDbMappingDAO(String dataSource, String userName) {
        this(dataSource, userName, new ArrayList<AasDbUserRoleDAO>());
    }

    public AasDbMappingDAO(String dataSource, String userName, List<AasDbUserRoleDAO> roles) {
        _dataSource = dataSource;
        _userName = userName;
        _roles = roles;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public int getId() {
        return _id;
    }

    public void setId(int id) {
        _id = id;
    }


    @Column(name = "USER_NAME")
    public String getUserName() { return _userName; }

    public void setUserName(String _userName) { this._userName = _userName; }

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "USER_ROLE",
            joinColumns = { @JoinColumn(name = "USER_ID") },
            inverseJoinColumns = { @JoinColumn(name = "USER_ROLE_ID") })
    public List<AasDbUserRoleDAO> getRoles() {
        return _roles;
    }

    public void setRoles(List<AasDbUserRoleDAO> roles) {
        _roles = roles;
    }

    @Column(name = "DATA_SOURCE")
    public String getDataSource() {
        return _dataSource;
    }

    public void setDataSource(String dataSource) {
        this._dataSource = dataSource;
    }
}
